const crypt = require('./utils/aesUtil');
const lz = require('./utils/lzString');
const args = process.argv.slice(2);
const CryptJS = require("crypto-js");
const md5 = str => CryptJS.MD5(str).toString();

//666810ddd21d4\/66616204c63a4\/65fde8394a4d1
function de(content) {
    return lz.decompressFromBase64(crypt.decrypt(content))
}

function en(content) {
    return crypt.encrypt(lz.compressToBase64(content))
}

function en64(content) {
    return crypt.encrypt(lz.compressToBase64(atob(content)))
}

if (args.length <= 1) {
    console.log("command: <method> <params>..")
    return;
} else {
    switch (args[0]) {
        case 'en':
            console.log(en(args[1]))
            return;
            break;
        case 'en64':
            console.log(en64(args[1]))
            return;
            break;
        case 'de':
            console.log(de(args[1]))
            return;
            break;
        case 'aes':
            if (args[1] === 'en') {
                console.log(CryptJS.AES.encrypt(args[2], args[3]).toString())
            } else {
                console.log(CryptJS.AES.decrypt(args[2], args[3]).toString())
            }
            return;
            break;
        case 'md5':
            console.log(md5(args[1]));
            break;
        default:
            console.log("not method")
            break;
    }
}
